package com.qf.lanzhou.blog.api.dao.Impl;

import com.qf.lanzhou.blog.api.dao.PraiseCountDao;
import com.qf.lanzhou.blog.api.pojo.entity.Praise;
import com.qf.lanzhou.blog.api.util.DruidUtil;
import org.apache.commons.dbutils.*;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

/**
 * @Author jian
 * @Date 2020/12/17 15:27
 * @JDK 1.8
 * @Version 1.0
 */
public class PraiseCountDaoimpl implements PraiseCountDao {
    private QueryRunner queryRunner = new QueryRunner(DruidUtil.getDataSource());
    @Override
    public Praise selectcount(String articleId, String praiseStatus) {
        String sql = "SELECT count(article_id) as count FROM t_praise where article_id=? and  praise_status=1";
        BeanProcessor bean = new GenerousBeanProcessor();
        RowProcessor processor = new BasicRowProcessor(bean);

        try {
            return queryRunner.query(sql,new BeanHandler<Praise>(Praise.class),articleId);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return null;
    }

}
